package top.yehot.kettle.boot.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import top.yehot.cmm.util.spring.anns.ResponseResult;
import top.yehot.kettle.boot.core.SysConst;
import top.yehot.kettle.boot.models.vo.script.ScriptRenameVO;
import top.yehot.kettle.boot.models.vo.script.ScriptUploadVO;
import top.yehot.kettle.boot.models.vo.script.ScriptVO;
import top.yehot.kettle.boot.service.ScriptService;

/**
 * 文件管理
 * 
 * @author lquan
 * @date 2022年6月1日 下午10:25:36
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping(SysConst.VERSION + "/script")
@AllArgsConstructor
@ResponseResult
public class ScriptController {
	
	private final ScriptService scriptService;

	@ApiOperation("查询目录下的脚本")
	@GetMapping("findScriptById")
	public List<ScriptVO> findScriptById(@RequestParam("repId") String repId, @RequestParam("dirId") String dirId) {
		return scriptService.findScriptById(repId, dirId);
	}
	
	@ApiOperation("删除脚本")
	@GetMapping("delete")
	public void delete(@RequestParam("repId") String repId, @RequestParam("fileId") String fileId) {
		scriptService.delete(repId, fileId);
	}
	
	@ApiOperation("上传文件")
	@PostMapping("upload")
	public void upload(@Valid ScriptUploadVO param) {
		scriptService.upload(param);
	}
	
	@ApiOperation("重命名")
	@GetMapping("rename")
	public void rename(ScriptRenameVO param) {
		scriptService.rename(param);
	}
	
}
